﻿using MVCManage.DAL;
using MVCManage.Model;
using MVCManage.Model.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVCManage.BLL
{
    public class HJQ_sales_reportBLL : BaseBLL<HJQ_sales_report>
    {
        public override void SetDal()
        {
            Dal = new HJQ_sales_reportDAL();
        }
       
   
        /// <summary>
        /// 销售报表
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="limit">页数</param>
        /// <param name="SlalasName">店铺名称</param>
        /// <param name="ProductName">商品名称</param>
        /// <param name="SalesDate">年份</param>
        /// <param name="maxgood">销冠</param>
        /// <returns></returns>
        public List<HJQ_sales_report> page(int page ,int limit ,out int count,string SlalasName ,  string ProductName,string SalesDate,string orderType) 
        {
         
            var data = Dal.Query();
            if (!string.IsNullOrWhiteSpace(ProductName)) 
            {
                data = data.Where(a => a.ProductName.Contains(ProductName));
            }
            if (!string.IsNullOrWhiteSpace(SlalasName))
            {
                data = data.Where(a => a.HJQ_store_info.shopName.Contains(SlalasName));
            }
    
            if (SalesDate.Length>3)
             {
                if (SalesDate.Contains("全部"))
                {
                    //查全部
                }
                else {
                    var time = DateTime.Parse(SalesDate);
                    data = data.Where(a => a.SalesDate.Year == time.Year && a.SalesDate.Month == time.Month);
                }
                 
            
             }
            if (orderType .Length> 1) 
            {
                data = data.Where(a => a.OrderType==orderType);
            }
         
                count=data.Count();
               var list = data.OrderBy(a=>a.SalesID).Skip((page-1)*limit).Take(limit).ToList();
               return list;
        }
    }
}
